﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tools.Base
{
    public class MyTime
    {
        //static DateTime StartTime = new DateTime(1970, 1, 1);

        /// <summary>
        /// UnixTime
        /// </summary>
        static public long CurUnixTime
        {
            get
            {
                DateTime StartTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                long nUnixStamp = (long)(DateTime.Now - StartTime).TotalSeconds;
                return nUnixStamp;
            }
        }

        static public int MakeYear(DateTime time)
        {
            return time.Year;
        }

        static public int MakeYearMonth(DateTime time)
        {
            return MakeYear(time) * 100 + time.Month;
        }

        static public int MakeYearMonthDay(DateTime time)
        {
            return MakeYearMonth(time) * 100 + time.Day;
        }

        static public long GetDateDayHourMinute(DateTime time)
        {
            return (long)MakeYearMonthDay(time) * 10000 + time.Hour * 100 + time.Minute;
        }

        public static DateTime ParseYearMonthDayHourMinute(long ymdhm)
        {
            int year, month, day, hour, minute;

            {
                long ymd = ymdhm / 10000;
                year = (int)ymd / 10000; ymd = ymd % 10000;
                month = (int)ymd / 100; ymd = ymd % 100;
                day = (int)ymd;
            }

            {
                long hm = ymdhm % 10000;
                hour = (int)hm / 100; hm = hm % 100;
                minute = (int)hm;
            }

            return new DateTime(year, month, day, hour, minute, 0);
        }
    }
}
